/*River Warren
 *October 15, 2011
 *
 *Key.h
 *Key object to be used by the game Dungeons and Princesses
*/

#ifndef KEY_H_INCLUDED
#define KEY_H_INCLUDED

#include "Base.h"
#include <iostream>
#include <string.h>
#include <stdlib.h>


#define DELIMS ",\n"
#define MAX 250

using std::string;
using std::ostream;
using std::istream;
using std::endl;

class Key: public Base
{

private:
    string keyCode;
    
    friend ostream& operator<<(ostream& out, Key& k)
    {
        out << k.getObjectID() << ',' << k.getObjectType() << ',' << k.getDesc() << ',' << k.keyCode;
        return out;
    }
    
    friend istream& operator>>(istream& in, Key &k)
    {
        char *tk = NULL;// pointers to chars
        char data[MAX] = ""; //to hold line
        in.getline(data,MAX - 1, '\n');
        tk = strtok(data, DELIMS);  //get first token of new line
        k.setObjectID(atoi(tk));
        tk = strtok(NULL, DELIMS); // get next token
        k.setObjectType(tk);
        tk = strtok(NULL, DELIMS); // get next token
        k.setDesc(tk);
        tk = strtok(NULL, DELIMS); // get next token
        k.keyCode = tk;
        return in;
    }
protected:
    void setKeyCode(string newKeyCode){keyCode = newKeyCode;}

public:
    Key() : Base("Key") {}
    
    Key(std::string keyDesc, std::string keyCodeToSet) : Base("Key") {
        
        Base::setDesc(keyDesc);
        
        setKeyCode(keyCodeToSet);
        
    }
        ~Key(){}
        string getKeyCode(){return keyCode;}
};

#endif // KEY_H_INCLUDED
